package com.example.cooldemo;

import android.os.Bundle;
import android.widget.TextView;

import com.example.cool_core.config.CoolViewConfig;
import com.example.cool_core.http.CoolHttpObserver;
import com.google.gson.Gson;
import com.ld.cool_library.http.HttpResModel;
import com.ld.cool_library.http.RxHttp;
import com.ld.cool_library.http.model.DemoModel;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class TopBaseHttpActivity extends BaseActivity {
    private TextView tv_text;

    @Override
    protected int setLayoutId(Bundle savedInstanceState) {
        CoolViewConfig.getInstance()
                .setDefault();
        return R.layout.activity_top_base;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        mPublicConfig.setTopBar("demo");
        tv_text = findViewById(R.id.tv_text);
        mRefreshUtil.onRefresh();
    }

    @Override
    public void onHttpRefresh(int page) {
        super.onHttpRefresh(page);
        RxHttp.init().list("1", "1418816972", "3741f5d13dc389e3d0ae68cfd8571725")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CoolHttpObserver<HttpResModel<DemoModel>>(mActivity, mPublicConfig) {
                    @Override
                    protected void HttpSuccess(HttpResModel<DemoModel> demoModelHttpResModel) {
                        super.HttpSuccess(demoModelHttpResModel);
                        tv_text.setText(new Gson().toJson(demoModelHttpResModel));
                    }
                });
    }
}
